<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
    <link rel="stylesheet" href="../lib/layui-v2.5.4/css/layui.css">
    <script src="../lib/layui-v2.5.4/layui.js"></script>
    <script src="https://cdn.bootcss.com/axios/0.19.0/axios.min.js"></script>


</head>

<body>
<form style="margin-top: 20px"  class="layui-form" action="" lay-filter="departmentForm">
    <input id="pId" class="pId" value="" hidden="hidden">
    <label class="layui-form-label">部门名称：</label>
    <div class="layui-input-inline" style="margin-bottom: 20px;width: 70%">
        <input id="pName" type="text" name="username" lay-verify="required" placeholder="请输入部门名称" autocomplete="off"
               class="layui-input pName">
    </div>
    <label class="layui-form-label">部门描述：</label>
    <div class="layui-input-block" style="margin-bottom: 20px; width: 70%">
        <textarea id="pRemark" placeholder="请输入描述内容" class="layui-textarea pRemark"></textarea>
    </div>
</form>
<script>
    function getValues() {
        var pName = $("#pName").val();
        var pRemark = $("#pRemark").val();
        var spId = $("#pId").val();
        var data = {"spName": pName, "spRemark":pRemark,"spId":spId};
        return data;
    }
    function setValues(datas) {
        $("#pName").val(datas.pname);
        $("#pRemark").val(datas.premark);
        $("#pId").val(datas.pid);
    }
    layui.use(['layer'],function () {
        var layer = layui.layer;

        $(function(){
            $("#pName").blur(function(){
                var data = getValues();
                if(data.spName == ""){
                    layer.msg("请输入部门名称");
                    return ;
                }
                axios.get('/api/department/queryPartByName', {
                    params: {
                        pName: data.spName
                    }
                })
                    .then(function (response) {
                        if(response.data.tt > 0){
                            layer.msg("部门已存在，请勿重复添加！");
                            return;
                        }
                    })
                    .catch(function (error) {
                    })
                    .then(function () {
                    });
            });
            $("#pRemark").blur(function(){
                var data = getValues();
                if(data.spRemark == ""){
                    layer.msg("请输入部门描述");
                    return ;
                }
            });
        });
    })

</script>
</body>
</html>